import { ref } from 'vue';
import dayjs from 'dayjs';
import { downLoadExcel, get } from '@/service/api/api';

const specificationOptions = ref([]);

function getSpecificationOptions() {
  get('/qms/agv/Grinder/findSize', {}).then(({ data, error }) => {
    if (!error) {
      specificationOptions.value = data.map(item => {
        return {
          label: item.grinderSize,
          value: item.grinderSize
        };
      });
    }
  });
}

const searchParam = ref({
  machineNumber: null,
  dateClass: null,
  grindTimes: null,
  date1: null,
  specification: null
});

export default {
  showTableToolsBtn: false,
  url: '/qms/agv/Grinder/findSummarzie',
  canRowDblclick: false,
  searchFormList: [
    {
      type: 'input',
      key: 'machineNumber',
      label: '机台号',
      placeholder: '请输入机台号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'input',
      key: 'serialNum',
      label: '单据号',
      placeholder: '请输入单据号',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4
    },
    {
      type: 'datePicker',
      key: 'date1',
      label: '日期',
      span: 24,
      md: 12,
      lg: 10,
      xl: 8,
      xxl: 3
    },
    {
      type: 'select',
      key: 'dateClass',
      label: '班别',
      placeholder: '请选择班别',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 3,
      selectOptions: [
        {
          value: 'A',
          label: 'A班'
        },
        {
          value: 'B',
          label: 'B班'
        }
      ]
    },
    {
      type: 'select',
      key: 'specification',
      label: '规格',
      placeholder: '请选择规格',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4,
      search: true,
      selectOptions: specificationOptions
    },
    {
      type: 'select',
      key: 'grindTimes',
      label: '研磨次数',
      placeholder: '请选择研磨次数',
      span: 24,
      md: 12,
      lg: 8,
      xl: 8,
      xxl: 4,
      search: true,
      selectOptions: [
        {
          label: '0',
          value: '0'
        },
        {
          label: '1',
          value: '1'
        },
        {
          label: '2',
          value: '2'
        },
        {
          label: '3',
          value: '3'
        },
        {
          label: '4',
          value: '4'
        },
        {
          label: '5',
          value: '5'
        },
        {
          label: '6',
          value: '6'
        }
      ]
    }
  ],
  searchParam,
  column: [
    {
      key: 'dataIndex',
      dataIndex: 'dataIndex',
      title: '序号',
      width: 70,
      fixed: 'left',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'machineNumber',
      dataIndex: 'machineNumber',
      title: '机台号',
      width: 120,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'serialNum',
      dataIndex: 'serialNum',
      title: '单据号',
      width: 130,
      align: 'center',
      fixed: 'left',
      checked: true,
      ellipsis: true
    },
    {
      key: 'date',
      dataIndex: 'date',
      title: '日期',
      width: 130,
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'dateClass',
      dataIndex: 'dateClass',
      title: '班次',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'unit',
      dataIndex: 'unit',
      title: '单位',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'specification',
      dataIndex: 'specification',
      title: '规格',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'grindTimes',
      dataIndex: 'grindTimes',
      title: '研磨次数',
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'grindNum',
      dataIndex: 'grindNum',
      title: '研磨数量',
      align: 'center',
      checked: true,
      ellipsis: true
    },

    {
      key: 'qualifiedNum',
      dataIndex: 'qualifiedNum',
      title: '合格数量',
      align: 'center',
      checked: true,
      ellipsis: true
    },
    {
      key: 'rate',
      dataIndex: 'rate',
      title: '合格率',
      align: 'center',
      checked: true,
      ellipsis: true
    }
    // {
    //   key: 'remark',
    //   dataIndex: 'remark',
    //   title: '备注',
    //   width: 180,
    //   align: 'center',
    //   checked: true,
    //   ellipsis: true
    // },
    // {
    //   key: 'createTime',
    //   dataIndex: 'createTime',
    //   title: '创建时间',
    //   width: 180,
    //   align: 'center',
    //   checked: true,
    //   ellipsis: true
    // }
    // {
    //   key: 'updateBy',
    //   dataIndex: 'updateBy',
    //   title: '修改人',
    //   width: 100,
    //   align: 'center',
    //   checked: true,
    //   ellipsis: true
    // }
  ],
  isProductionTable: false,
  scroll: { x: 'auto', y: 'auto' },
  otherBtnList: [
    {
      icon: 'icon-ic-round-download ',
      name: '导出',
      iconType: 3,
      auth: 'grinding-machine:download',
      handleClick: () => {
        downLoadExcel(
          `/qms/agv/Exporter/exportExcel`,
          {
            formId: 92,
            ...searchParam.value
          },
          `研磨机汇总${dayjs().format('YYYY-MM-DD HH:mm:ss')}.xlsx`
        );
      }
    }
  ],
  pageMounted() {
    getSpecificationOptions();
  }
};
